<template>
  <view style="padding-bottom: 10rpx;">
    <!-- 收支碳能量数量-->
    <uni-card :is-shadow="false">
      <span style="margin-right: 15rpx;">支付金额：</span>
      <template v-if="dataDetails.payType == 1">
        <span class="common-money errorColor">{{ parseFloat(Number(dataDetails.amount).toFixed(0)) }}</span>&nbsp;g
        碳能量
      </template>
      <template v-else>
        <span class="common-money themeColor">{{ dataDetails.amount }}</span>&nbsp;元
      </template>
    </uni-card>

    <!-- 基本信息-->
    <uni-card title="基本信息" :is-shadow="false">
      <view>订单编号：<span>{{ dataDetails.number }}</span></view>
      <view>订单名称：<span>{{ dataDetails.name }}</span></view>
      <view>支付金额：
        <span v-if="dataDetails.payType == 1">{{ parseFloat(Number(dataDetails.amount).toFixed(0)) }} g 碳能量</span>
        <span v-else>{{ dataDetails.amount }} 元</span>
      </view>
      <view>发票状态：
        <template v-for="(item, index) in dicts.ec_invoice_status">
          <template v-if="dataDetails.invoiceStatus == item.value">
            <uni-tag :text="item.text" size="small" :type="item.type"/>
          </template>
        </template>
      </view>
      <view>支付类型：
        <template v-for="(item, index) in dicts.ec_order_pay_type">
          <template v-if="dataDetails.payType == item.value">
            <uni-tag :text="item.text" :type="item.type"/>
          </template>
        </template>
      </view>
      <view>订单状态：
        <template v-for="(item, index) in dicts.ec_order_status">
          <template v-if="dataDetails.status == item.value">
            <uni-tag :text="item.text" size="small" :type="item.type"/>
          </template>
        </template>
      </view>
      <view>下单人：<span>{{ dataDetails.orderPersonName }}</span></view>
      <view>支付人：<span>{{ dataDetails.payerName }}</span></view>
      <view>交易时间：<span>{{ dataDetails.createTime }}</span></view>
      <view>支付时间：<span>{{ dataDetails.payTime }}</span></view>
    </uni-card>

    <!-- 关联订单信息-->
    <uni-card v-if="!!orderPay" title="关联订单信息" :is-shadow="false">
      <template v-if="!!orderPay">
        <!--签署流量包-->
        <view v-if="dataDetails.orderType == 0">
          <view>套餐编号：<span>{{ orderPay.number }}</span></view>
          <view>套餐名称：<span>{{ orderPay.signFlowFeeName }}</span></view>
          <view>订单状态：
            <template v-for="(item, index) in dicts.ec_sign_order_status">
              <template v-if="orderPay.status == item.value">
                <uni-tag :text="item.text" size="small" :type="item.type"/>
              </template>
            </template>
          </view>
          <view>套餐剩余量：<span>{{ orderPay.remainingNum + ' 次' }}</span></view>
          <view>套餐总量：<span>{{ orderPay.signCountNum + ' 次 （套餐总量 = 签署量 + 赠送量）' }}</span></view>
          <view>签署量：<span>{{ orderPay.signNum + ' 次' }}</span></view>
          <view>赠送量：<span>{{ orderPay.giveSignNum + ' 次' }}</span></view>
          <view>交易时间：<span>{{ orderPay.createTime }}</span></view>
          <view>过期时间：<span>{{ orderPay.expirationTime }}</span></view>
          <view>描述：<span>{{ orderPay.remark }}</span></view>
        </view>
        <!--出证服务-->
        <view v-if="dataDetails.orderType == 1">
          <!--基本信息-->
          <template>
            <view>订单编号：<span>{{ orderPay.number }}</span></view>
            <view>出证服务名称：<span>{{ orderPay.evidenceFeeName }}</span></view>
            <view>证书类型：
              <template v-for="(item, index) in dicts.ec_evidence_type">
                <template v-if="orderPay.evidenceFeeType == item.value">
                  <uni-tag :text="item.text" size="small" :type="item.type"/>
                </template>
              </template>
            </view>
            <view>订单状态：
              <template v-for="(item, index) in dicts.ec_evidence_status">
                <template v-if="orderPay.status == item.value">
                  <uni-tag :text="item.text" size="small" :type="item.type"/>
                </template>
              </template>
            </view>
            <view>申请时间：<span>{{ orderPay.createTime }}</span></view>
            <view>完成时间：<span>{{ (!!orderPay.completeTime) ? orderPay.completeTime : '--' }}</span></view>
          </template>
          <!--出证合同信息-->
          <template>
            <view>出证合同名称：<span>{{ orderPay.contractName }}</span></view>
            <view>出证合同编号：<span>{{ orderPay.contractNumber }}</span></view>
            <view>签署方名字：<span>{{ orderPay.contractSignName }}</span></view>
          </template>
          <!--出证人信息-->
          <template v-if="!!buyer">
            <view>申请出证人：<span>{{ buyer.name }}</span></view>
            <view>出证人手机号：<span>{{ buyer.mobileHide }}</span></view>
          </template>
          <!--委托申请授权书-->
          <template v-if="!!entrustContract">
            <view>授权书名称：<span>{{ entrustContract.contractName }}</span></view>
            <view>签署状态：
              <template v-for="(item, index) in dicts.contract_sign_flow_status">
                <template v-if="entrustContract.status == item.value">
                  <uni-tag :text="item.text" size="small" :type="item.type"/>
                </template>
              </template>
            </view>
            <view>签署时间：<span>{{ entrustContract.sealTime }}</span></view>
          </template>
          <!--物流信息-->
          <template v-if="orderPay.evidenceFeeType == 2">
            <view>收货地址：<span>{{ orderPay.staffAddress }}</span></view>
            <view>物流公司：<span>{{ orderPay.trackingName }}</span></view>
            <view>物流公司：<span>{{ orderPay.trackingName }}</span></view>
            <view>物流单号：
              <span>{{ orderPay.trackingNumber }}</span>
              <el-button
                  type="primary"
                  :disabled="orderPay.trackingNumber == null"
                  v-clipboard:copy="orderPay.trackingNumber"
                  v-clipboard:success="clipboardSuccess"
                  v-clipboard:error="clipboardError"
              >复制
              </el-button>
            </view>
            <view>签署状态：
              <template v-for="(item, index) in dicts.contract_sign_flow_status">
                <template v-if="entrustContract.status == item.value">
                  <uni-tag :text="item.text" size="small" :type="item.type"/>
                </template>
              </template>
            </view>
            <view>签署时间：<span>{{ entrustContract.sealTime }}</span></view>
          </template>
        </view>
        <!--范本信息-->
        <view v-if="dataDetails.orderType == 2">
          <view>订单编号：<span>{{ orderPay.number }}</span></view>
          <view>范本名称：<span>{{ orderPay.title }}</span></view>
          <view>总页数：<span>{{ orderPay.pagerNum + ' 页' }}</span></view>
          <view>支付状态：
            <template v-for="(item, index) in dicts.ec_order_status">
              <template v-if="orderPay.payStatus == item.value">
                <uni-tag :text="item.text" size="small" :type="item.type"/>
              </template>
            </template>
          </view>
          <view>交易时间：<span>{{ orderPay.createTime }}</span></view>
          <view>范本简介：<span>{{ orderPay.introduce }}</span></view>
        </view>
      </template>
    </uni-card>
  </view>
</template>

<script>
import {getOrderPay} from "@/api/ec/person/fee/orderPay";
import {getFlowFeeOrder} from "@/api/ec/person/fee/signFlowFeeOrder";
import {getTemplateMarketOrder} from "@/api/ec/work/template/templateMarketOrder";
import {getInfoNoContent} from "@/api/ec/work/template/templateMarket";
import {getEvidenceFeeOrder} from "@/api/ec/work/evidenceOut/evidenceFeeOrder";
import {getStaffNoDept} from "@/api/ec/console/org/staff";
import {getContractSignMine} from "@/api/ec/work/contract/contractSign";
import {getDictsByNameForUni} from "../../../../../utils/dicts";

export default {
  data() {
    return {
      // 数据字典
      dicts: {
        // 支付类型
        ec_order_pay_type: [],
        // 订单支付状态
        ec_order_status: [],
        // 发票状态
        ec_invoice_status: [],
        // 签署订单那状态
        ec_sign_order_status: [],
        // 出证证书类型
        ec_evidence_type: [],
        // 出证订单状态
        ec_evidence_status: [],
        // 签署状态
        contract_sign_flow_status: [],
      },
      // 详情数据
      dataDetails: {},
      // 关联订单信息
      orderPay: null,
      // 出证人
      buyer: null,
      // 委托申请授权书
      entrustContract: null,
    }
  },
  onLoad(option) {
    // 获取参数
    this.dataDetails = JSON.parse(option.dataDetails)
    // 加载字典数据
    this.getDicts()
  },
  created() {
    this.getRecordDetails();
  },
  methods: {
    // ===============================================================================================================
    // ==== 加载数据字典
    // ===============================================================================================================
    /**加载数据字典*/
    getDicts() {
      // 支付类型
      this.dicts.ec_order_pay_type = getDictsByNameForUni("ec_order_pay_type");
      // 订单支付状态
      this.dicts.ec_order_status = getDictsByNameForUni("ec_order_status");
      // 发票状态
      this.dicts.ec_invoice_status = getDictsByNameForUni("ec_invoice_status");
      // 签署订单那状态
      this.dicts.ec_sign_order_status = getDictsByNameForUni("ec_sign_order_status");
      // 出证证书类型
      this.dicts.ec_evidence_type = getDictsByNameForUni("ec_evidence_type");
      // 出证订单状态
      this.dicts.ec_evidence_status = getDictsByNameForUni("ec_evidence_status");
      // 委托申请授权书
      this.dicts.contract_sign_flow_status = getDictsByNameForUni("contract_sign_flow_status");
    },
    /** 获取订单详情 */
    getRecordDetails() {
      getOrderPay(this.dataDetails.id).then(response => {
        this.dataDetails = response.data;
        // 查询签署套餐订单详细
        if (this.dataDetails.orderType == 0) {
          this.getFlowFeeOrderInfo();
        }
        // 查询出证服务订单详细
        if (this.dataDetails.orderType == 1) {
          this.getEvidenceFeeOrderInfo();
        }
        // 查询购买范本订单详细
        if (this.dataDetails.orderType == 2) {
          this.getTemplateMarketOrderInfo();
        }
      });
    },
    /** 查询流量包订单详细 */
    getFlowFeeOrderInfo() {
      this.$modal.loading();
      getFlowFeeOrder(this.dataDetails.orderId).then(response => {
        uni.hideLoading()
        this.orderPay = response.data;
      }).catch(() => {
        uni.hideLoading()
      });
    },
    /** 查询范本订单详细 */
    getTemplateMarketOrderInfo() {
      this.$modal.loading();
      getTemplateMarketOrder(this.dataDetails.orderId).then(response => {
        uni.hideLoading()
        this.getTemplateMarketInfo(response.data.templateMarketId, response.data);
      }).catch(() => {
        uni.hideLoading()
      });
    },
    /** 查询合同范文市场详细（无Content） */
    getTemplateMarketInfo(id, data) {
      getInfoNoContent(id).then(response => {
        data.title = response.data.title;
        data.pagerNum = response.data.pagerNum;
        data.introduce = response.data.introduce;
        this.orderPay = data;
      });
    },
    /** 查询出证服务订单详细 */
    getEvidenceFeeOrderInfo() {
      this.$modal.loading();
      getEvidenceFeeOrder(this.dataDetails.orderId).then(response => {
        uni.hideLoading()
        this.orderPay = response.data;
        if (!!this.orderPay.buyerId) {
          this.findUserInfo(this.orderPay.buyerId);
        }
        if (!!this.orderPay.entrustContractFlowId) {
          this.findEntrustContract(this.orderPay.entrustContractFlowId);
        }
      }).catch(() => {
        uni.hideLoading()
      });
    },
    /** 查询出证人用户认证信息 */
    findUserInfo(id) {
      getStaffNoDept(id).then(response => {
        this.buyer = response.data;
      });
    },
    /** 查询委托申请授权书 */
    findEntrustContract(id) {
      getContractSignMine(id).then(response => {
        this.entrustContract = response.data;
      });
    },
    /** 复制失败 */
    clipboardError() {
      this.$modal.msgError("复制失败");
    },
    /** 复制链接成功 */
    clipboardSuccess() {
      this.$modal.msgSuccess("复制成功");
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .uni-collapse-item__title-box {
  background: #fff;
  padding: 0;
}

::v-deep .uniui-bottom {
  color: #ccc !important;
}

page {
  background: $uni-bg-color;
}

view {
  margin-bottom: 16rpx;
}

.common-money {
  font-size: 40rpx;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  line-height: 40rpx;
  margin-right: 15rpx;
}

</style>
